//
//  HDCFFundDetailDeader.m
//  HaoDeCaiFu
//
//  Created by 郑开宏 on 2017/11/1.
//  Copyright © 2017年 郑开宏. All rights reserved.
//

#import "HDCFFundDetailDeader.h"

@interface HDCFFundDetailDeader ()

@property (nonatomic, assign) BOOL isCollct;

@property (nonatomic, strong) NSDictionary *fundTypeDict;

@end

@implementation HDCFFundDetailDeader

- (NSDictionary *)fundTypeDict{
    if (!_fundTypeDict) {
        self.fundTypeDict = @{@"MM":@"货币型",
                              @"BOND":@"债券型",
                              @"MIXED":@"混合型",
                              @"CP":@"保本型",
                              @"EQ":@"股票型",
                              @"AI":@"另类型",
                              @"INDEX":@"指数型",
                              @"ST":@"分级型",
                              @"UNKNOWN":@"其他"
                              };
    }
    return _fundTypeDict;
}

+ (instancetype)HDCFFundDetailDeader{
    return [[NSBundle mainBundle] loadNibNamed:@"HDCFFundDetailDeader" owner:nil options:nil].firstObject;
}

- (void)setIsLiCai:(BOOL)isLiCai{
    _isLiCai = isLiCai;
    if (isLiCai == YES) {
        self.collectionBtn.hidden = YES;
        self.shoucangBtn.hidden = YES;
        self.imgView.hidden = YES;
    }
}

- (void)setDataDict:(NSDictionary *)dataDict{
    _dataDict = dataDict;
    _nameL.text = dataDict[@"fundName"];
    NSNumber *riskRate = dataDict[@"riskRate"];
    if (riskRate.integerValue == 1) {
        _riskLevel.text = @"低风险";
    }else if (riskRate.integerValue == 2){
        _riskLevel.text = @"中低风险";
    }else if (riskRate.integerValue == 3){
        _riskLevel.text = @"中风险";
    }else if (riskRate.integerValue == 4){
        _riskLevel.text = @"中高风险";
    }else{
        _riskLevel.text = @"高风险";
    }
    
    if (_isLiCai == YES) {
        _fundType.text = [NSString stringWithFormat:@"%@", dataDict[@"fundCode"]];
    }else{
        _fundType.text = [NSString stringWithFormat:@"%@ | %@", dataDict[@"fundCode"], self.fundTypeDict[dataDict[@"fundType"]]];
    }
    

    NSNumber *nav = dataDict[@"nav"];

    _valueNewL.text = [NSString stringWithFormat:@"最新净值：%.4f", nav.doubleValue];
    _valueNewL.adjustsFontSizeToFitWidth = YES;

    NSNumber *day1Performance = dataDict[@"day1Performance"];
    _dayIncrease.font = _valueNewL.font;
    if ([day1Performance isKindOfClass:[NSNull class]]) {
        _dayIncrease.text = @"日涨幅：0.00%";
    }else
    {
        _dayIncrease.text = [NSString stringWithFormat:@"日涨幅：%.2f%%", day1Performance.doubleValue];
    }
    NSNumber *navDate = dataDict[@"navDate"];
    NSDateFormatter *stampFormatter = [[NSDateFormatter alloc] init];
    [stampFormatter setDateFormat:@"YYYY-MM-dd"];
    NSDate *stampDate2 = [NSDate dateWithTimeIntervalSince1970:[navDate doubleValue] / 1000];
    NSString *dateString = [stampFormatter stringFromDate:stampDate2];
    
    _timeL.text = dateString;
    _timeL.font = _valueNewL.font;
}

- (void)awakeFromNib{
    [super awakeFromNib];
    
//    [self.collectionBtn setImage:[UIImage imageNamed:@"icon_shoucang_dis"] forState:UIControlStateNormal];
//    [self.collectionBtn.titleLabel setFont:[UIFont systemFontOfSize:13]];
//    self.collectionBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
//    [self.collectionBtn setTitleEdgeInsets:UIEdgeInsetsMake(self.collectionBtn.imageView.frame.size.height + 5, -self.collectionBtn.imageView.frame.size.width, 0.0, 0.0)];//文字距离上边框的距离增加imageView的高度，距离左边框减少imageView的宽度，距离下边框和右边框距离不变
//    [self.collectionBtn setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, self.collectionBtn.titleLabel.frame.size.height + 5, -self.collectionBtn.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度，其它不边
    self.riskLevel.layer.cornerRadius = 5.0;
    self.riskLevel.clipsToBounds = YES;
}
- (IBAction)colecBtnClick:(UIButton *)sender {
    if (self.isCollct == YES) {
        self.isCollct = NO;
        self.imgView.image = [UIImage imageNamed:@"icon_shoucang_dis"];
    }else{
        self.isCollct = YES;
        self.imgView.image = [UIImage imageNamed:@"icon_shoucang_sel"];
    }
}

@end
